import Router from '@koa/router';
import { validateDto } from '../../../middleware/validation';
import { AuthMiddleware } from '../../../middleware/authMiddleware';
import { MenuController } from '../../../controllers/system/menuController';
// import { UserController } from '../../controllers/userController';
import { CreateMenuDto, UpdateMenuDto } from '../../../dtos/system/MenuDto';

const router = new Router();
// const userController = new UserController();
const authMiddleware = new AuthMiddleware();
const menuController = new MenuController();

// 获取所有菜单（需要认证）
router.get('/', authMiddleware.authenticate, menuController.getMenus);

// 根据ID获取菜单（需要认证）
router.get('/:id', authMiddleware.authenticate, menuController.getMenuById);


router.post('/', authMiddleware.authenticate, authMiddleware.requireRole('admin'), validateDto(CreateMenuDto), menuController.createMenu);

// 更新菜单（需要认证，仅管理员）
router.put('/:id', authMiddleware.authenticate,  validateDto(UpdateMenuDto, { skipMissingProperties: true }), menuController.updateMenu);

// 删除菜单（需要认证，仅管理员）
router.delete('/:id', authMiddleware.authenticate, authMiddleware.requireRole('admin'), menuController.deleteMenu);

export default router;